Music Recommendation System For Meditation & Relaxation¶

Understanding the Dataset¶

Dataset Overview¶

The dataset contains information related to Spotify tracks used for building a music recommendation system tailored for meditation and relaxation purposes. It includes a comprehensive set of attributes that describe various aspects of each track.

Dataset Columns¶

  1. user_id: Unique identifier for Spotify users.

  2. Track Name: Name of the track.

  3. Artist Name(s): Name of the artist(s) associated with the track.

  4. Album Name: Name of the album to which the track belongs.

  5. Album Release Date: Release date of the album.

  6. Track Number: Unique track number within the album.

  7. Track Duration (ms): Duration of the track in milliseconds.

  8. Explicit: Indicator if the track contains explicit content.

  9. Popularity: Measure indicating how popular a track is based on its play count.

  10. Added By: User who added the track to a playlist.

  11. Added At: Timestamp when the track was added to the playlist.

  12. Danceability: Metric describing how suitable a track is for dancing based on tempo, rhythm stability, beat strength, and overall regularity.

  13. Energy: Perceptual measure of intensity and activity in the track.

  14. Key: The key in which the track is performed. Integers map to pitches using standard Pitch Class notation.

  15. Loudness: Loudness of the track in decibels (dB).

  16. Mode: Indicates the modality (major or minor) of the track.

  17. Speechiness: Presence of spoken words in the track, measured as the ratio of speech-like sounds to music-like sounds.

  18. Acousticness: Confidence measure from 0.0 to 1.0 indicating whether the track is acoustic.

  19. Instrumentalness: Predicts whether a track contains vocals. Higher values suggest instrumental tracks.

  20. Liveness: Detects the presence of an audience in the recording. Higher values represent higher probability of a live audience.

  21. Valence: Measure from 0.0 to 1.0 describing the musical positiveness conveyed by a track.

  22. Tempo: Beats per minute (BPM) of the track.

  23. Time Signature: Estimated overall time signature of the track.

Usage Context¶

This dataset is pivotal for developing a music recommendation system that caters specifically to meditation and relaxation needs. By analyzing attributes such as acousticness, instrumentalness, and valence, the system aims to recommend tracks that align with calming and soothing musical preferences.

Spotify Dataset¶

In [1]:
from PIL import Image
Spotify_data = Image.open("C://Users//dell//Downloads//Screenshot (1).png");
Spotify_data
Out[1]:
In [2]:
import pandas as pd
import numpy as np
In [3]:
#importing and merging two csv files
df = pd.concat(
    map(pd.read_csv,['meditationandrelaxation1.csv', 'meditationandrelaxation2.csv', 'meditationandrelaxation3.csv', 'meditationandrelaxation4.csv', 'meditationandrelaxation5.csv']), ignore_index=True)
print(df)
                                   Track URI                   Track Name  \
0       spotify:track:4wDkM4eonFlMpw07mQxZbM            Meditation Awaken   
1       spotify:track:0dLkW1wbEi6nzyLQOwNCMv                 Yoga Top 100   
2     spotify:episode:6tpsPNJECk1eLbsPJgXNBR  Meditation - Naval Ravikant   
3       spotify:track:1oVgCauMXygkALiOtI51M1                 Yoga Top 100   
4     spotify:episode:5fLpnfOalU991SfSu9r7z8       Meditation - by A Monk   
...                                      ...                          ...   
1282    spotify:track:52bpdusCUIPfzrRZ8n4FRP                       Maitri   
1283    spotify:track:71kayL70PNWQIHWt5P8uhU            Spiritual Teacher   
1284    spotify:track:77PyhSbcu8ctjPbVGSwaa9                       Chakra   
1285    spotify:track:3vmjzmOGGlPczWQWNf7cE0                       Elixir   
1286    spotify:track:5AJIr4CC0Te4HOofAtmYa8                    Kundalini   

                                          Artist URI(s)  \
0                 spotify:artist:568O2cGvLWBRq81ESU0Dlw   
1     spotify:artist:3uilhWYZIH4z0KQRoywFC8, spotify...   
2                   spotify:show:7IG2XdnbjH3eTubEopFAuB   
3                 spotify:artist:30u03dHVwT6ByMPQYs7e2P   
4                   spotify:show:7IG2XdnbjH3eTubEopFAuB   
...                                                 ...   
1282  spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify...   
1283  spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify...   
1284  spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify...   
1285  spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify...   
1286  spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify...   

                                         Artist Name(s)  \
0                          Chakra Healing Music Academy   
1     Yoga Training Music Ensemble, Healing Yoga Med...   
2                Self Improvement through Top 100 Books   
3                                  Namaste Healing Yoga   
4                Self Improvement through Top 100 Books   
...                                                 ...   
1282  Yoga Ambience, Soothing White Noise for Infant...   
1283  Yoga Ambience, Soothing White Noise for Infant...   
1284  Yoga Ambience, Soothing White Noise for Infant...   
1285  Yoga Ambience, Soothing White Noise for Infant...   
1286  Yoga Ambience, Soothing White Noise for Infant...   

                                 Album URI  \
0     spotify:album:5iVlr7HTEOSDECK1ImyUoR   
1     spotify:album:2BG3DdCdDNpVOKVjnSZSs8   
2      spotify:show:7IG2XdnbjH3eTubEopFAuB   
3     spotify:album:4zH8WhBULRyaEtZOivWESO   
4      spotify:show:7IG2XdnbjH3eTubEopFAuB   
...                                    ...   
1282  spotify:album:2MYoqNTjhmycukFlHOsrbu   
1283  spotify:album:2MYoqNTjhmycukFlHOsrbu   
1284  spotify:album:2MYoqNTjhmycukFlHOsrbu   
1285  spotify:album:2MYoqNTjhmycukFlHOsrbu   
1286  spotify:album:2MYoqNTjhmycukFlHOsrbu   

                                             Album Name  \
0     Genius Brain Frequency: Top 100 Chakra Healing...   
1     Anxiety Meditation and Yoga for Insecurity: Re...   
2                Self Improvement through Top 100 Books   
3     Zen Meditation Music 111: Relaxing Flute Piano...   
4                Self Improvement through Top 100 Books   
...                                                 ...   
1282                                    # Fresh Therapy   
1283                                    # Fresh Therapy   
1284                                    # Fresh Therapy   
1285                                    # Fresh Therapy   
1286                                    # Fresh Therapy   

                                    Album Artist URI(s)  \
0                 spotify:artist:568O2cGvLWBRq81ESU0Dlw   
1     spotify:artist:3uilhWYZIH4z0KQRoywFC8, spotify...   
2                   spotify:show:7IG2XdnbjH3eTubEopFAuB   
3                 spotify:artist:0LyfQWJT6nXafLPZqxe9Of   
4                   spotify:show:7IG2XdnbjH3eTubEopFAuB   
...                                                 ...   
1282  spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify...   
1283  spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify...   
1284  spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify...   
1285  spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify...   
1286  spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify...   

                                   Album Artist Name(s) Album Release Date  \
0                          Chakra Healing Music Academy         2022-01-04   
1     Yoga Training Music Ensemble, Healing Yoga Med...         2021-09-07   
2                Self Improvement through Top 100 Books                NaN   
3                                       Various Artists         2016-05-23   
4                Self Improvement through Top 100 Books                NaN   
...                                                 ...                ...   
1282  Yoga Ambience, Soothing White Noise for Infant...         2019-10-09   
1283  Yoga Ambience, Soothing White Noise for Infant...         2019-10-09   
1284  Yoga Ambience, Soothing White Noise for Infant...         2019-10-09   
1285  Yoga Ambience, Soothing White Noise for Infant...         2019-10-09   
1286  Yoga Ambience, Soothing White Noise for Infant...         2019-10-09   

                                        Album Image URL  ...   Key  Loudness  \
0     https://i.scdn.co/image/ab67616d0000b273b7a6a6...  ...   0.0   -23.311   
1     https://i.scdn.co/image/ab67616d0000b273f68cbf...  ...   5.0   -22.049   
2     https://i.scdn.co/image/ab6765630000ba8a087cce...  ...   NaN       NaN   
3     https://i.scdn.co/image/ab67616d0000b273f5a637...  ...  10.0   -24.113   
4     https://i.scdn.co/image/ab6765630000ba8a087cce...  ...   NaN       NaN   
...                                                 ...  ...   ...       ...   
1282  https://i.scdn.co/image/ab67616d0000b27336f563...  ...   2.0   -18.944   
1283  https://i.scdn.co/image/ab67616d0000b27336f563...  ...   2.0   -20.522   
1284  https://i.scdn.co/image/ab67616d0000b27336f563...  ...  11.0   -29.692   
1285  https://i.scdn.co/image/ab67616d0000b27336f563...  ...  10.0   -21.052   
1286  https://i.scdn.co/image/ab67616d0000b27336f563...  ...   3.0   -28.018   

      Mode Speechiness  Acousticness  Instrumentalness Liveness Valence  \
0      1.0      0.0366         0.986             0.872   0.0884  0.0368   
1      1.0      0.0499         0.922             0.917   0.1010  0.0372   
2      NaN         NaN           NaN               NaN      NaN     NaN   
3      1.0      0.0421         0.843             0.947   0.1300  0.0534   
4      NaN         NaN           NaN               NaN      NaN     NaN   
...    ...         ...           ...               ...      ...     ...   
1282   1.0      0.0424         0.929             0.954   0.0922  0.0384   
1283   0.0      0.0433         0.991             0.989   0.0851  0.0340   
1284   0.0      0.0446         0.968             0.975   0.1370  0.0342   
1285   0.0      0.0769         0.990             0.915   0.1290  0.0492   
1286   1.0      0.0387         0.982             0.986   0.1150  0.0496   

        Tempo  Time Signature  
0      75.166             4.0  
1      88.407             4.0  
2         NaN             NaN  
3     102.475             3.0  
4         NaN             NaN  
...       ...             ...  
1282   70.205             5.0  
1283   75.706             3.0  
1284   64.739             3.0  
1285   65.566             5.0  
1286   68.935             4.0  

[1287 rows x 30 columns]
In [4]:
df.head()
Out[4]:
Track URI Track Name Artist URI(s) Artist Name(s) Album URI Album Name Album Artist URI(s) Album Artist Name(s) Album Release Date Album Image URL ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time Signature
0 spotify:track:4wDkM4eonFlMpw07mQxZbM Meditation Awaken spotify:artist:568O2cGvLWBRq81ESU0Dlw Chakra Healing Music Academy spotify:album:5iVlr7HTEOSDECK1ImyUoR Genius Brain Frequency: Top 100 Chakra Healing... spotify:artist:568O2cGvLWBRq81ESU0Dlw Chakra Healing Music Academy 2022-01-04 https://i.scdn.co/image/ab67616d0000b273b7a6a6... ... 0.0 -23.311 1.0 0.0366 0.986 0.872 0.0884 0.0368 75.166 4.0
1 spotify:track:0dLkW1wbEi6nzyLQOwNCMv Yoga Top 100 spotify:artist:3uilhWYZIH4z0KQRoywFC8, spotify... Yoga Training Music Ensemble, Healing Yoga Med... spotify:album:2BG3DdCdDNpVOKVjnSZSs8 Anxiety Meditation and Yoga for Insecurity: Re... spotify:artist:3uilhWYZIH4z0KQRoywFC8, spotify... Yoga Training Music Ensemble, Healing Yoga Med... 2021-09-07 https://i.scdn.co/image/ab67616d0000b273f68cbf... ... 5.0 -22.049 1.0 0.0499 0.922 0.917 0.1010 0.0372 88.407 4.0
2 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books NaN https://i.scdn.co/image/ab6765630000ba8a087cce... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 spotify:track:1oVgCauMXygkALiOtI51M1 Yoga Top 100 spotify:artist:30u03dHVwT6ByMPQYs7e2P Namaste Healing Yoga spotify:album:4zH8WhBULRyaEtZOivWESO Zen Meditation Music 111: Relaxing Flute Piano... spotify:artist:0LyfQWJT6nXafLPZqxe9Of Various Artists 2016-05-23 https://i.scdn.co/image/ab67616d0000b273f5a637... ... 10.0 -24.113 1.0 0.0421 0.843 0.947 0.1300 0.0534 102.475 3.0
4 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books NaN https://i.scdn.co/image/ab6765630000ba8a087cce... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

5 rows × 30 columns

EDA (Exploratory Data Analysis)¶

In [5]:
#finding total NaN values in dataset
df.isna().sum()
Out[5]:
Track URI                 0
Track Name                0
Artist URI(s)             0
Artist Name(s)            0
Album URI                 0
Album Name                0
Album Artist URI(s)       0
Album Artist Name(s)      0
Album Release Date       95
Album Image URL           0
Disc Number               0
Track Number              0
Track Duration (ms)       0
Track Preview URL         1
Explicit                  0
Popularity                0
Added By                  0
Added At                  0
Danceability            155
Energy                  155
Key                     155
Loudness                155
Mode                    155
Speechiness             155
Acousticness            155
Instrumentalness        155
Liveness                155
Valence                 155
Tempo                   155
Time Signature          155
dtype: int64
In [6]:
#displaying all rows having all NaN values 
df[df.isnull().any(axis=1)]
Out[6]:
Track URI Track Name Artist URI(s) Artist Name(s) Album URI Album Name Album Artist URI(s) Album Artist Name(s) Album Release Date Album Image URL ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time Signature
2 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books NaN https://i.scdn.co/image/ab6765630000ba8a087cce... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
4 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books NaN https://i.scdn.co/image/ab6765630000ba8a087cce... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
5 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books NaN https://i.scdn.co/image/ab6765630000ba8a087cce... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
109 spotify:episode:5Krsp55kY3goGGqkBV26ej 15 Minute Super Deep Meditation Music: Relax M... spotify:show:1dKiVyh2JEe4KrPKrvm3aB Mediation spotify:show:1dKiVyh2JEe4KrPKrvm3aB Mediation spotify:show:1dKiVyh2JEe4KrPKrvm3aB Mediation NaN https://i.scdn.co/image/698b78f04cca0c2af50e23... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
174 spotify:episode:3oVSxuDiphnEI9WrvFVdqo Healing Sounds: Cleans the Aura and Space. Rem... spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF NaN https://i.scdn.co/image/4514ca814660f983cdb29e... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1151 spotify:episode:3oVSxuDiphnEI9WrvFVdqo Healing Sounds: Cleans the Aura and Space. Rem... spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF NaN https://i.scdn.co/image/4514ca814660f983cdb29e... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1152 spotify:episode:3oVSxuDiphnEI9WrvFVdqo Healing Sounds: Cleans the Aura and Space. Rem... spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF NaN https://i.scdn.co/image/4514ca814660f983cdb29e... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1153 spotify:episode:3oVSxuDiphnEI9WrvFVdqo Healing Sounds: Cleans the Aura and Space. Rem... spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF spotify:show:4O9ewm6rHndbj2AiagZiUG MEDITATION SELF NaN https://i.scdn.co/image/4514ca814660f983cdb29e... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1155 spotify:episode:35YCJuheZCJD5HsnkaS3P7 [Study Sleep Relax 💖] Meditation - music spotify:show:64ijNYNNSIzrNFEcXwB6YL Relaxing music spotify:show:64ijNYNNSIzrNFEcXwB6YL Relaxing music spotify:show:64ijNYNNSIzrNFEcXwB6YL Relaxing music NaN https://i.scdn.co/image/ab6765630000ba8aeed951... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1156 spotify:episode:07HQ80zuAB7D0KgDNPlMFz Relaxing Sleep Music • Deep Sleeping Music, Re... spotify:show:1WTKOss6rssszbgoVh0QN0 Comforting Sounds spotify:show:1WTKOss6rssszbgoVh0QN0 Comforting Sounds spotify:show:1WTKOss6rssszbgoVh0QN0 Comforting Sounds NaN https://i.scdn.co/image/ab6765630000ba8ab1883f... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

156 rows × 30 columns

In [7]:
#coverting dtype of object to datetime 
df['Album Release Date'] = pd.to_datetime(df['Album Release Date'])
df.dtypes
Out[7]:
Track URI                       object
Track Name                      object
Artist URI(s)                   object
Artist Name(s)                  object
Album URI                       object
Album Name                      object
Album Artist URI(s)             object
Album Artist Name(s)            object
Album Release Date      datetime64[ns]
Album Image URL                 object
Disc Number                      int64
Track Number                     int64
Track Duration (ms)              int64
Track Preview URL               object
Explicit                          bool
Popularity                       int64
Added By                        object
Added At                        object
Danceability                   float64
Energy                         float64
Key                            float64
Loudness                       float64
Mode                           float64
Speechiness                    float64
Acousticness                   float64
Instrumentalness               float64
Liveness                       float64
Valence                        float64
Tempo                          float64
Time Signature                 float64
dtype: object
In [8]:
df.shape
Out[8]:
(1287, 30)
In [9]:
df.describe()
Out[9]:
Disc Number Track Number Track Duration (ms) Popularity Danceability Energy Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time Signature
count 1287.000000 1287.000000 1.287000e+03 1287.000000 1132.000000 1132.000000 1132.000000 1132.000000 1132.000000 1132.000000 1132.000000 1132.000000 1132.000000 1132.000000 1132.000000 1132.000000
mean 0.926185 15.230769 5.855823e+05 12.702409 0.232496 0.176255 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 3.645760
std 0.261571 15.529144 1.613435e+06 14.743136 0.137524 0.214033 3.544642 6.867583 0.468284 0.075965 0.250707 0.267468 0.186740 0.115242 30.279224 0.903353
min 0.000000 0.000000 3.100000e+04 0.000000 0.000000 0.000059 0.000000 -47.004000 0.000000 0.000000 0.000000 0.000000 0.044400 0.000000 0.000000 0.000000
25% 1.000000 4.000000 1.358560e+05 0.000000 0.149000 0.040325 2.000000 -29.018250 0.000000 0.039200 0.804750 0.806000 0.098300 0.035500 74.071000 3.000000
50% 1.000000 11.000000 2.124120e+05 4.000000 0.190000 0.108000 4.000000 -24.751500 1.000000 0.044500 0.937000 0.908000 0.111000 0.039800 87.654500 4.000000
75% 1.000000 23.000000 2.580705e+05 25.000000 0.271000 0.209000 8.000000 -20.209500 1.000000 0.053200 0.980000 0.953000 0.150000 0.109000 115.969750 4.000000
max 1.000000 284.000000 1.277986e+07 59.000000 0.808000 1.000000 11.000000 -6.989000 1.000000 0.937000 0.996000 1.000000 0.976000 0.907000 186.565000 5.000000
In [10]:
#displaying column name
df.columns
Out[10]:
Index(['Track URI', 'Track Name', 'Artist URI(s)', 'Artist Name(s)',
       'Album URI', 'Album Name', 'Album Artist URI(s)',
       'Album Artist Name(s)', 'Album Release Date', 'Album Image URL',
       'Disc Number', 'Track Number', 'Track Duration (ms)',
       'Track Preview URL', 'Explicit', 'Popularity', 'Added By', 'Added At',
       'Danceability', 'Energy', 'Key', 'Loudness', 'Mode', 'Speechiness',
       'Acousticness', 'Instrumentalness', 'Liveness', 'Valence', 'Tempo',
       'Time Signature'],
      dtype='object')
In [11]:
df.dtypes
Out[11]:
Track URI                       object
Track Name                      object
Artist URI(s)                   object
Artist Name(s)                  object
Album URI                       object
Album Name                      object
Album Artist URI(s)             object
Album Artist Name(s)            object
Album Release Date      datetime64[ns]
Album Image URL                 object
Disc Number                      int64
Track Number                     int64
Track Duration (ms)              int64
Track Preview URL               object
Explicit                          bool
Popularity                       int64
Added By                        object
Added At                        object
Danceability                   float64
Energy                         float64
Key                            float64
Loudness                       float64
Mode                           float64
Speechiness                    float64
Acousticness                   float64
Instrumentalness               float64
Liveness                       float64
Valence                        float64
Tempo                          float64
Time Signature                 float64
dtype: object
In [12]:
#creating random user names
nodes=['{0}'.format(i) for i in range(1,151)]
In [13]:
print(nodes)
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '120', '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '150']
In [14]:
import numpy as np
In [15]:
#inserting random user name 
df["user"] = np.random.choice(nodes, size=len(df))
In [16]:
df.dtypes
Out[16]:
Track URI                       object
Track Name                      object
Artist URI(s)                   object
Artist Name(s)                  object
Album URI                       object
Album Name                      object
Album Artist URI(s)             object
Album Artist Name(s)            object
Album Release Date      datetime64[ns]
Album Image URL                 object
Disc Number                      int64
Track Number                     int64
Track Duration (ms)              int64
Track Preview URL               object
Explicit                          bool
Popularity                       int64
Added By                        object
Added At                        object
Danceability                   float64
Energy                         float64
Key                            float64
Loudness                       float64
Mode                           float64
Speechiness                    float64
Acousticness                   float64
Instrumentalness               float64
Liveness                       float64
Valence                        float64
Tempo                          float64
Time Signature                 float64
user                            object
dtype: object
In [17]:
df.head()
Out[17]:
Track URI Track Name Artist URI(s) Artist Name(s) Album URI Album Name Album Artist URI(s) Album Artist Name(s) Album Release Date Album Image URL ... Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time Signature user
0 spotify:track:4wDkM4eonFlMpw07mQxZbM Meditation Awaken spotify:artist:568O2cGvLWBRq81ESU0Dlw Chakra Healing Music Academy spotify:album:5iVlr7HTEOSDECK1ImyUoR Genius Brain Frequency: Top 100 Chakra Healing... spotify:artist:568O2cGvLWBRq81ESU0Dlw Chakra Healing Music Academy 2022-01-04 https://i.scdn.co/image/ab67616d0000b273b7a6a6... ... -23.311 1.0 0.0366 0.986 0.872 0.0884 0.0368 75.166 4.0 41
1 spotify:track:0dLkW1wbEi6nzyLQOwNCMv Yoga Top 100 spotify:artist:3uilhWYZIH4z0KQRoywFC8, spotify... Yoga Training Music Ensemble, Healing Yoga Med... spotify:album:2BG3DdCdDNpVOKVjnSZSs8 Anxiety Meditation and Yoga for Insecurity: Re... spotify:artist:3uilhWYZIH4z0KQRoywFC8, spotify... Yoga Training Music Ensemble, Healing Yoga Med... 2021-09-07 https://i.scdn.co/image/ab67616d0000b273f68cbf... ... -22.049 1.0 0.0499 0.922 0.917 0.1010 0.0372 88.407 4.0 29
2 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books NaT https://i.scdn.co/image/ab6765630000ba8a087cce... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 102
3 spotify:track:1oVgCauMXygkALiOtI51M1 Yoga Top 100 spotify:artist:30u03dHVwT6ByMPQYs7e2P Namaste Healing Yoga spotify:album:4zH8WhBULRyaEtZOivWESO Zen Meditation Music 111: Relaxing Flute Piano... spotify:artist:0LyfQWJT6nXafLPZqxe9Of Various Artists 2016-05-23 https://i.scdn.co/image/ab67616d0000b273f5a637... ... -24.113 1.0 0.0421 0.843 0.947 0.1300 0.0534 102.475 3.0 150
4 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books NaT https://i.scdn.co/image/ab6765630000ba8a087cce... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 8

5 rows × 31 columns

In [18]:
df.user
Out[18]:
0        41
1        29
2       102
3       150
4         8
       ... 
1282    136
1283    133
1284     45
1285     64
1286     36
Name: user, Length: 1287, dtype: object
In [19]:
df
Out[19]:
Track URI Track Name Artist URI(s) Artist Name(s) Album URI Album Name Album Artist URI(s) Album Artist Name(s) Album Release Date Album Image URL ... Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time Signature user
0 spotify:track:4wDkM4eonFlMpw07mQxZbM Meditation Awaken spotify:artist:568O2cGvLWBRq81ESU0Dlw Chakra Healing Music Academy spotify:album:5iVlr7HTEOSDECK1ImyUoR Genius Brain Frequency: Top 100 Chakra Healing... spotify:artist:568O2cGvLWBRq81ESU0Dlw Chakra Healing Music Academy 2022-01-04 https://i.scdn.co/image/ab67616d0000b273b7a6a6... ... -23.311 1.0 0.0366 0.986 0.872 0.0884 0.0368 75.166 4.0 41
1 spotify:track:0dLkW1wbEi6nzyLQOwNCMv Yoga Top 100 spotify:artist:3uilhWYZIH4z0KQRoywFC8, spotify... Yoga Training Music Ensemble, Healing Yoga Med... spotify:album:2BG3DdCdDNpVOKVjnSZSs8 Anxiety Meditation and Yoga for Insecurity: Re... spotify:artist:3uilhWYZIH4z0KQRoywFC8, spotify... Yoga Training Music Ensemble, Healing Yoga Med... 2021-09-07 https://i.scdn.co/image/ab67616d0000b273f68cbf... ... -22.049 1.0 0.0499 0.922 0.917 0.1010 0.0372 88.407 4.0 29
2 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books NaT https://i.scdn.co/image/ab6765630000ba8a087cce... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 102
3 spotify:track:1oVgCauMXygkALiOtI51M1 Yoga Top 100 spotify:artist:30u03dHVwT6ByMPQYs7e2P Namaste Healing Yoga spotify:album:4zH8WhBULRyaEtZOivWESO Zen Meditation Music 111: Relaxing Flute Piano... spotify:artist:0LyfQWJT6nXafLPZqxe9Of Various Artists 2016-05-23 https://i.scdn.co/image/ab67616d0000b273f5a637... ... -24.113 1.0 0.0421 0.843 0.947 0.1300 0.0534 102.475 3.0 150
4 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books spotify:show:7IG2XdnbjH3eTubEopFAuB Self Improvement through Top 100 Books NaT https://i.scdn.co/image/ab6765630000ba8a087cce... ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 8
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1282 spotify:track:52bpdusCUIPfzrRZ8n4FRP Maitri spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify... Yoga Ambience, Soothing White Noise for Infant... spotify:album:2MYoqNTjhmycukFlHOsrbu # Fresh Therapy spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify... Yoga Ambience, Soothing White Noise for Infant... 2019-10-09 https://i.scdn.co/image/ab67616d0000b27336f563... ... -18.944 1.0 0.0424 0.929 0.954 0.0922 0.0384 70.205 5.0 136
1283 spotify:track:71kayL70PNWQIHWt5P8uhU Spiritual Teacher spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify... Yoga Ambience, Soothing White Noise for Infant... spotify:album:2MYoqNTjhmycukFlHOsrbu # Fresh Therapy spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify... Yoga Ambience, Soothing White Noise for Infant... 2019-10-09 https://i.scdn.co/image/ab67616d0000b27336f563... ... -20.522 0.0 0.0433 0.991 0.989 0.0851 0.0340 75.706 3.0 133
1284 spotify:track:77PyhSbcu8ctjPbVGSwaa9 Chakra spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify... Yoga Ambience, Soothing White Noise for Infant... spotify:album:2MYoqNTjhmycukFlHOsrbu # Fresh Therapy spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify... Yoga Ambience, Soothing White Noise for Infant... 2019-10-09 https://i.scdn.co/image/ab67616d0000b27336f563... ... -29.692 0.0 0.0446 0.968 0.975 0.1370 0.0342 64.739 3.0 45
1285 spotify:track:3vmjzmOGGlPczWQWNf7cE0 Elixir spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify... Yoga Ambience, Soothing White Noise for Infant... spotify:album:2MYoqNTjhmycukFlHOsrbu # Fresh Therapy spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify... Yoga Ambience, Soothing White Noise for Infant... 2019-10-09 https://i.scdn.co/image/ab67616d0000b27336f563... ... -21.052 0.0 0.0769 0.990 0.915 0.1290 0.0492 65.566 5.0 64
1286 spotify:track:5AJIr4CC0Te4HOofAtmYa8 Kundalini spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify... Yoga Ambience, Soothing White Noise for Infant... spotify:album:2MYoqNTjhmycukFlHOsrbu # Fresh Therapy spotify:artist:2r4ianXqpG3DPlOZ41ljI9, spotify... Yoga Ambience, Soothing White Noise for Infant... 2019-10-09 https://i.scdn.co/image/ab67616d0000b27336f563... ... -28.018 1.0 0.0387 0.982 0.986 0.1150 0.0496 68.935 4.0 36

1287 rows × 31 columns

In [20]:
#droping unwanted columns in the dataset
music=df.drop(["Artist URI(s)","Album URI","Album Artist URI(s)","Album Artist Name(s)","Album Image URL","Disc Number","Track Preview URL"],axis=1)
music.columns
Out[20]:
Index(['Track URI', 'Track Name', 'Artist Name(s)', 'Album Name',
       'Album Release Date', 'Track Number', 'Track Duration (ms)', 'Explicit',
       'Popularity', 'Added By', 'Added At', 'Danceability', 'Energy', 'Key',
       'Loudness', 'Mode', 'Speechiness', 'Acousticness', 'Instrumentalness',
       'Liveness', 'Valence', 'Tempo', 'Time Signature', 'user'],
      dtype='object')
In [21]:
#poping last user column 
first_column=music.pop("user")
In [22]:
music.columns
Out[22]:
Index(['Track URI', 'Track Name', 'Artist Name(s)', 'Album Name',
       'Album Release Date', 'Track Number', 'Track Duration (ms)', 'Explicit',
       'Popularity', 'Added By', 'Added At', 'Danceability', 'Energy', 'Key',
       'Loudness', 'Mode', 'Speechiness', 'Acousticness', 'Instrumentalness',
       'Liveness', 'Valence', 'Tempo', 'Time Signature'],
      dtype='object')
In [23]:
#inserting user column at first place 
music.insert(0,"user", first_column)
In [24]:
music.columns
Out[24]:
Index(['user', 'Track URI', 'Track Name', 'Artist Name(s)', 'Album Name',
       'Album Release Date', 'Track Number', 'Track Duration (ms)', 'Explicit',
       'Popularity', 'Added By', 'Added At', 'Danceability', 'Energy', 'Key',
       'Loudness', 'Mode', 'Speechiness', 'Acousticness', 'Instrumentalness',
       'Liveness', 'Valence', 'Tempo', 'Time Signature'],
      dtype='object')
In [25]:
len(music)
Out[25]:
1287
In [26]:
df.dtypes
Out[26]:
Track URI                       object
Track Name                      object
Artist URI(s)                   object
Artist Name(s)                  object
Album URI                       object
Album Name                      object
Album Artist URI(s)             object
Album Artist Name(s)            object
Album Release Date      datetime64[ns]
Album Image URL                 object
Disc Number                      int64
Track Number                     int64
Track Duration (ms)              int64
Track Preview URL               object
Explicit                          bool
Popularity                       int64
Added By                        object
Added At                        object
Danceability                   float64
Energy                         float64
Key                            float64
Loudness                       float64
Mode                           float64
Speechiness                    float64
Acousticness                   float64
Instrumentalness               float64
Liveness                       float64
Valence                        float64
Tempo                          float64
Time Signature                 float64
user                            object
dtype: object
In [27]:
#coverting dtype of object to datetime 
music['Added At'] =pd.to_datetime(music['Added At'])
In [28]:
df.dtypes
Out[28]:
Track URI                       object
Track Name                      object
Artist URI(s)                   object
Artist Name(s)                  object
Album URI                       object
Album Name                      object
Album Artist URI(s)             object
Album Artist Name(s)            object
Album Release Date      datetime64[ns]
Album Image URL                 object
Disc Number                      int64
Track Number                     int64
Track Duration (ms)              int64
Track Preview URL               object
Explicit                          bool
Popularity                       int64
Added By                        object
Added At                        object
Danceability                   float64
Energy                         float64
Key                            float64
Loudness                       float64
Mode                           float64
Speechiness                    float64
Acousticness                   float64
Instrumentalness               float64
Liveness                       float64
Valence                        float64
Tempo                          float64
Time Signature                 float64
user                            object
dtype: object
In [29]:
#extrating date from datetime format
music["Added At"]=music["Added At"].dt.date
In [30]:
music["Added At"]
Out[30]:
0       2022-02-12
1       2022-02-12
2       2022-02-12
3       2022-02-12
4       2022-02-12
           ...    
1282    2022-02-15
1283    2022-02-15
1284    2022-02-15
1285    2022-02-15
1286    2022-02-15
Name: Added At, Length: 1287, dtype: object
In [31]:
#coverting datatype (object to datetime), displaying only date 
music['Added At'] = pd.to_datetime(music['Added At'])
In [32]:
#filling Na values in Time Signature with 0
music['Time Signature'] = music['Time Signature'].fillna(0)
In [33]:
#converting datatype of Time Signature column from float to int
music['Time Signature'] = music['Time Signature'].astype(np.int64)
In [34]:
music.dtypes
Out[34]:
user                           object
Track URI                      object
Track Name                     object
Artist Name(s)                 object
Album Name                     object
Album Release Date     datetime64[ns]
Track Number                    int64
Track Duration (ms)             int64
Explicit                         bool
Popularity                      int64
Added By                       object
Added At               datetime64[ns]
Danceability                  float64
Energy                        float64
Key                           float64
Loudness                      float64
Mode                          float64
Speechiness                   float64
Acousticness                  float64
Instrumentalness              float64
Liveness                      float64
Valence                       float64
Tempo                         float64
Time Signature                  int64
dtype: object
In [35]:
music
Out[35]:
user Track URI Track Name Artist Name(s) Album Name Album Release Date Track Number Track Duration (ms) Explicit Popularity ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time Signature
0 41 spotify:track:4wDkM4eonFlMpw07mQxZbM Meditation Awaken Chakra Healing Music Academy Genius Brain Frequency: Top 100 Chakra Healing... 2022-01-04 20 225000 False 5 ... 0.0 -23.311 1.0 0.0366 0.986 0.872 0.0884 0.0368 75.166 4
1 29 spotify:track:0dLkW1wbEi6nzyLQOwNCMv Yoga Top 100 Yoga Training Music Ensemble, Healing Yoga Med... Anxiety Meditation and Yoga for Insecurity: Re... 2021-09-07 3 255384 False 1 ... 5.0 -22.049 1.0 0.0499 0.922 0.917 0.1010 0.0372 88.407 4
2 102 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant Self Improvement through Top 100 Books Self Improvement through Top 100 Books NaT 0 415056 False 0 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0
3 150 spotify:track:1oVgCauMXygkALiOtI51M1 Yoga Top 100 Namaste Healing Yoga Zen Meditation Music 111: Relaxing Flute Piano... 2016-05-23 25 252512 False 8 ... 10.0 -24.113 1.0 0.0421 0.843 0.947 0.1300 0.0534 102.475 3
4 8 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk Self Improvement through Top 100 Books Self Improvement through Top 100 Books NaT 0 112941 False 0 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1282 136 spotify:track:52bpdusCUIPfzrRZ8n4FRP Maitri Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 26 346402 False 0 ... 2.0 -18.944 1.0 0.0424 0.929 0.954 0.0922 0.0384 70.205 5
1283 133 spotify:track:71kayL70PNWQIHWt5P8uhU Spiritual Teacher Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 27 285372 False 0 ... 2.0 -20.522 0.0 0.0433 0.991 0.989 0.0851 0.0340 75.706 3
1284 45 spotify:track:77PyhSbcu8ctjPbVGSwaa9 Chakra Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 28 272816 False 0 ... 11.0 -29.692 0.0 0.0446 0.968 0.975 0.1370 0.0342 64.739 3
1285 64 spotify:track:3vmjzmOGGlPczWQWNf7cE0 Elixir Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 29 253226 False 0 ... 10.0 -21.052 0.0 0.0769 0.990 0.915 0.1290 0.0492 65.566 5
1286 36 spotify:track:5AJIr4CC0Te4HOofAtmYa8 Kundalini Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 30 245496 False 0 ... 3.0 -28.018 1.0 0.0387 0.982 0.986 0.1150 0.0496 68.935 4

1287 rows × 24 columns

In [36]:
#rename all the columns which have space in between bcs it considers as a series type 

music=music.rename(columns= {"Track URI":"Track_URI","Track Name":"Track_Name","Artist Name(s)":"Artist_Name","Album Name":"Album_Name","Album Release Date":"Album_Release_Date","Track Number":"Track_Number","Track Duration (ms)":"Track_Duration(ms)","Added By":"Added_By","Added At":"Added_At","Time Signature":"Time_Signature","user":"user_id"})
#df.columns = df.columns.str.replace(' ','_')
In [37]:
music.head()
Out[37]:
user_id Track_URI Track_Name Artist_Name Album_Name Album_Release_Date Track_Number Track_Duration(ms) Explicit Popularity ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time_Signature
0 41 spotify:track:4wDkM4eonFlMpw07mQxZbM Meditation Awaken Chakra Healing Music Academy Genius Brain Frequency: Top 100 Chakra Healing... 2022-01-04 20 225000 False 5 ... 0.0 -23.311 1.0 0.0366 0.986 0.872 0.0884 0.0368 75.166 4
1 29 spotify:track:0dLkW1wbEi6nzyLQOwNCMv Yoga Top 100 Yoga Training Music Ensemble, Healing Yoga Med... Anxiety Meditation and Yoga for Insecurity: Re... 2021-09-07 3 255384 False 1 ... 5.0 -22.049 1.0 0.0499 0.922 0.917 0.1010 0.0372 88.407 4
2 102 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant Self Improvement through Top 100 Books Self Improvement through Top 100 Books NaT 0 415056 False 0 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0
3 150 spotify:track:1oVgCauMXygkALiOtI51M1 Yoga Top 100 Namaste Healing Yoga Zen Meditation Music 111: Relaxing Flute Piano... 2016-05-23 25 252512 False 8 ... 10.0 -24.113 1.0 0.0421 0.843 0.947 0.1300 0.0534 102.475 3
4 8 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk Self Improvement through Top 100 Books Self Improvement through Top 100 Books NaT 0 112941 False 0 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0

5 rows × 24 columns

In [38]:
music.sort_values('user_id', ascending=True) 
Out[38]:
user_id Track_URI Track_Name Artist_Name Album_Name Album_Release_Date Track_Number Track_Duration(ms) Explicit Popularity ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time_Signature
631 1 spotify:track:3xEcxC4SJKbl2kBrhzmNmL Sleep Aid Noise: 720 Hz Brown Noise Nuts Brown Noise: 720 Hz 2021-11-15 19 62000 False 14 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0
582 1 spotify:track:5LkuuUwdyM6cqx0RTMlqTZ Relaxation Therapy Music Five Senses Meditation Sanctuary Modern Meditation: Fast and Effective Relaxation 2019-08-12 3 203576 False 32 ... 10.0 -17.750 1.0 0.0364 0.989 0.94300 0.0795 0.2740 77.978 4
936 1 spotify:track:1B9OkJj4frUJjrqH6dCd7x Between Worlds, Native American Oriental Music Zone Indian Meditation Music Collection – Instrumen... 2017-08-21 17 235887 False 1 ... 1.0 -26.973 0.0 0.0469 0.938 0.97000 0.0967 0.1290 137.553 3
1141 1 spotify:track:7ilBLFs3Q9Mb3xa6si2ICT Power Of Peace - Original Mix Sanct Devotional Club Mindful Valley - Relaxing Meditating Music 2021-05-26 31 185600 False 0 ... 1.0 -14.974 1.0 0.0441 0.656 0.95600 0.1120 0.0367 62.693 3
1017 1 spotify:track:1lIikO2A66vDn2uwR3UZNt Sleeping Flute Music Deep Sleep Music DEA Channel, Flute Music Medi... Healing Indian Flute: Calming Native American ... 2021-12-16 1 165233 False 6 ... 0.0 -16.700 1.0 0.0415 0.986 0.91500 0.1060 0.0404 62.264 3
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
868 98 spotify:episode:6woGmcr5A67MkTa1uG4sdV Indian Flute Music For Deep Meditation, Relaxa... Prana Relaxation And Meditation Music Prana Relaxation And Meditation Music NaT 0 2827050 False 0 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0
861 98 spotify:track:0ttVqRISNySDktBhdJsJZv Sarvesham Svastir Bhavtu Meditative Mind Magical Mantras for Meditation - Volume Two 2015-11-30 4 2717900 False 39 ... 0.0 -21.798 1.0 0.0368 0.892 0.19500 0.0892 0.0315 102.618 4
489 98 spotify:track:5jxaN0paoMpjppAcyQ7eSL Headache & Migraine Natural Relief Headache Relief Unit Headache & Migraine Natural Relief: Calming So... 2017-10-09 1 225974 False 41 ... 3.0 -26.713 1.0 0.0394 0.987 0.94000 0.0920 0.0397 95.688 1
48 99 spotify:track:2jtYyevrJUjP5WoUZ47zmA Meditation on the Beach Buddha Music Sanctuary Meditation TOP 100: Buddha Calm & Peace, 7 Cha... 2016-01-19 44 217282 False 0 ... 11.0 -27.510 1.0 0.0816 0.942 0.00174 0.3330 0.0383 103.135 4
1108 99 spotify:track:2k4sKrKjj8STfBg0gTco4P Pure Feelings Relaxing Saxophone Jazz Meditating Saxophone Music 2020-07-14 8 159394 False 18 ... 9.0 -19.544 0.0 0.0675 0.962 0.02790 0.1350 0.5840 183.320 3

1287 rows × 24 columns

In [39]:
music["Added_At"]
Out[39]:
0      2022-02-12
1      2022-02-12
2      2022-02-12
3      2022-02-12
4      2022-02-12
          ...    
1282   2022-02-15
1283   2022-02-15
1284   2022-02-15
1285   2022-02-15
1286   2022-02-15
Name: Added_At, Length: 1287, dtype: datetime64[ns]

checking Na values in columns¶

In [40]:
music["Added_At"].isna().sum()
Out[40]:
0
In [41]:
music["Album_Release_Date"].isna().sum()
Out[41]:
95
In [42]:
date_mean=(music.Album_Release_Date-music.Album_Release_Date.min()).mean()+music.Album_Release_Date.min()
In [43]:
date_mean
Out[43]:
Timestamp('2019-01-12 01:07:39.060402688')
In [44]:
d='2019-01-12 01:07:39.060402688'
date=pd.to_datetime(d).date()
print(date)
2019-01-12
In [45]:
end = pd.to_datetime('2019-01-12')
music["Album_Release_Date"]=music["Album_Release_Date"].fillna(end)
In [46]:
music
Out[46]:
user_id Track_URI Track_Name Artist_Name Album_Name Album_Release_Date Track_Number Track_Duration(ms) Explicit Popularity ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time_Signature
0 41 spotify:track:4wDkM4eonFlMpw07mQxZbM Meditation Awaken Chakra Healing Music Academy Genius Brain Frequency: Top 100 Chakra Healing... 2022-01-04 20 225000 False 5 ... 0.0 -23.311 1.0 0.0366 0.986 0.872 0.0884 0.0368 75.166 4
1 29 spotify:track:0dLkW1wbEi6nzyLQOwNCMv Yoga Top 100 Yoga Training Music Ensemble, Healing Yoga Med... Anxiety Meditation and Yoga for Insecurity: Re... 2021-09-07 3 255384 False 1 ... 5.0 -22.049 1.0 0.0499 0.922 0.917 0.1010 0.0372 88.407 4
2 102 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0 415056 False 0 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0
3 150 spotify:track:1oVgCauMXygkALiOtI51M1 Yoga Top 100 Namaste Healing Yoga Zen Meditation Music 111: Relaxing Flute Piano... 2016-05-23 25 252512 False 8 ... 10.0 -24.113 1.0 0.0421 0.843 0.947 0.1300 0.0534 102.475 3
4 8 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0 112941 False 0 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1282 136 spotify:track:52bpdusCUIPfzrRZ8n4FRP Maitri Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 26 346402 False 0 ... 2.0 -18.944 1.0 0.0424 0.929 0.954 0.0922 0.0384 70.205 5
1283 133 spotify:track:71kayL70PNWQIHWt5P8uhU Spiritual Teacher Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 27 285372 False 0 ... 2.0 -20.522 0.0 0.0433 0.991 0.989 0.0851 0.0340 75.706 3
1284 45 spotify:track:77PyhSbcu8ctjPbVGSwaa9 Chakra Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 28 272816 False 0 ... 11.0 -29.692 0.0 0.0446 0.968 0.975 0.1370 0.0342 64.739 3
1285 64 spotify:track:3vmjzmOGGlPczWQWNf7cE0 Elixir Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 29 253226 False 0 ... 10.0 -21.052 0.0 0.0769 0.990 0.915 0.1290 0.0492 65.566 5
1286 36 spotify:track:5AJIr4CC0Te4HOofAtmYa8 Kundalini Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 30 245496 False 0 ... 3.0 -28.018 1.0 0.0387 0.982 0.986 0.1150 0.0496 68.935 4

1287 rows × 24 columns

In [47]:
#Replacing NaN values in Danceability column with mean value as column is of contineous type and non-categorical
Danceability_mean=music["Danceability"].mean()
music['Danceability'] = music['Danceability'].fillna(Danceability_mean)
In [48]:
#Replacing NaN values in Energy column with mean value as column is of contineous type and non-categorical
Energy_mean=music["Energy"].mean()
music['Energy'] = music['Energy'].fillna(Energy_mean)
In [49]:
#Replacing NaN values in key column with mean value as column is of contineous type and non-categorical
Key_mean=music["Key"].mean()
music['Key'] = music['Key'].fillna(Key_mean)
In [50]:
#Replacing NaN values in loudness column with mean value as column is of contineous type and non-categorical
Loudness_mean=music["Loudness"].mean()
music['Loudness'] = music['Loudness'].fillna(Loudness_mean)
In [51]:
#Replacing NaN values in Mode column with mean value as column is of contineous type and non-categorical
Mode_mean=music["Mode"].mean()
music['Mode'] = music['Mode'].fillna(Mode_mean)
In [52]:
#Replacing NaN valuesin Speechiness column with mean value as column is of contineous type and non-categorical
Speechiness_mean=music["Speechiness"].mean()
music['Speechiness'] = music['Speechiness'].fillna(Speechiness_mean)
In [53]:
#Replacing NaN values in Acousticness column with mean value as column is of contineous type and non-categorical
Acousticness_mean=music["Acousticness"].mean()
music['Acousticness'] = music['Acousticness'].fillna(Acousticness_mean)
In [54]:
#Replacing NaN values in Instrumentalness column with mean value as column is of contineous type and non-categorical
Instrumentalness_mean=music["Instrumentalness"].mean()
music['Instrumentalness'] = music['Instrumentalness'].fillna(Instrumentalness_mean)
In [55]:
#Replacing NaN values in Liveness column with mean value as column is of contineous type and non-categorical
Liveness_mean=music["Liveness"].mean()
music['Liveness'] = music['Liveness'].fillna(Liveness_mean)
In [56]:
#Replacing NaN values in valence column with mean value as column is of contineous type and non-categorical
Valence_mean=music["Valence"].mean()
music['Valence'] = music['Valence'].fillna(Valence_mean)
In [57]:
#Replacing NaN values in Tempo column with mean value as column is of contineous type and non-categorical
Tempo_mean=music["Tempo"].mean()
music['Tempo'] = music['Tempo'].fillna(Tempo_mean)
In [58]:
#Replacing NaN values in Time_Signature column with mode value as column is categorical 
Time_Signature_mode=music["Time_Signature"].mode()
Time_Signature_mode
Out[58]:
0    4
dtype: int64
In [59]:
music['Time_Signature'] = music['Time_Signature'].replace(0, 4)
In [60]:
music.isna().sum()
Out[60]:
user_id               0
Track_URI             0
Track_Name            0
Artist_Name           0
Album_Name            0
Album_Release_Date    0
Track_Number          0
Track_Duration(ms)    0
Explicit              0
Popularity            0
Added_By              0
Added_At              0
Danceability          0
Energy                0
Key                   0
Loudness              0
Mode                  0
Speechiness           0
Acousticness          0
Instrumentalness      0
Liveness              0
Valence               0
Tempo                 0
Time_Signature        0
dtype: int64
In [61]:
music
Out[61]:
user_id Track_URI Track_Name Artist_Name Album_Name Album_Release_Date Track_Number Track_Duration(ms) Explicit Popularity ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time_Signature
0 41 spotify:track:4wDkM4eonFlMpw07mQxZbM Meditation Awaken Chakra Healing Music Academy Genius Brain Frequency: Top 100 Chakra Healing... 2022-01-04 20 225000 False 5 ... 0.000000 -23.311000 1.000000 0.036600 0.986000 0.872000 0.088400 0.036800 75.166000 4
1 29 spotify:track:0dLkW1wbEi6nzyLQOwNCMv Yoga Top 100 Yoga Training Music Ensemble, Healing Yoga Med... Anxiety Meditation and Yoga for Insecurity: Re... 2021-09-07 3 255384 False 1 ... 5.000000 -22.049000 1.000000 0.049900 0.922000 0.917000 0.101000 0.037200 88.407000 4
2 102 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0 415056 False 0 ... 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4
3 150 spotify:track:1oVgCauMXygkALiOtI51M1 Yoga Top 100 Namaste Healing Yoga Zen Meditation Music 111: Relaxing Flute Piano... 2016-05-23 25 252512 False 8 ... 10.000000 -24.113000 1.000000 0.042100 0.843000 0.947000 0.130000 0.053400 102.475000 3
4 8 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0 112941 False 0 ... 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1282 136 spotify:track:52bpdusCUIPfzrRZ8n4FRP Maitri Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 26 346402 False 0 ... 2.000000 -18.944000 1.000000 0.042400 0.929000 0.954000 0.092200 0.038400 70.205000 5
1283 133 spotify:track:71kayL70PNWQIHWt5P8uhU Spiritual Teacher Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 27 285372 False 0 ... 2.000000 -20.522000 0.000000 0.043300 0.991000 0.989000 0.085100 0.034000 75.706000 3
1284 45 spotify:track:77PyhSbcu8ctjPbVGSwaa9 Chakra Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 28 272816 False 0 ... 11.000000 -29.692000 0.000000 0.044600 0.968000 0.975000 0.137000 0.034200 64.739000 3
1285 64 spotify:track:3vmjzmOGGlPczWQWNf7cE0 Elixir Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 29 253226 False 0 ... 10.000000 -21.052000 0.000000 0.076900 0.990000 0.915000 0.129000 0.049200 65.566000 5
1286 36 spotify:track:5AJIr4CC0Te4HOofAtmYa8 Kundalini Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 30 245496 False 0 ... 3.000000 -28.018000 1.000000 0.038700 0.982000 0.986000 0.115000 0.049600 68.935000 4

1287 rows × 24 columns

In [62]:
music=music.sort_values(by='Album_Release_Date',ascending=False)
music
Out[62]:
user_id Track_URI Track_Name Artist_Name Album_Name Album_Release_Date Track_Number Track_Duration(ms) Explicit Popularity ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time_Signature
730 2 spotify:track:4KxUNwVikOpJyM3AWF87h8 Relaxation Music, Pt. 16 Relaxing Music by Terry Woodbead, Yoga, Relaxi... #01 Relaxation Music to Unwind, for Sleeping, ... 2022-02-15 16 131852 False 0 ... 10.0 -37.285 0.0 0.0456 0.929 0.864 0.1050 0.0379 74.771 4
752 30 spotify:track:0xkRnMADm4cTmaI8damzQq Relaxation Music, Pt. 38 Relaxing Music by Terry Woodbead, Yoga, Relaxi... #01 Relaxation Music to Unwind, for Sleeping, ... 2022-02-15 38 144190 False 0 ... 2.0 -41.150 0.0 0.0426 0.913 0.757 0.0987 0.0346 141.659 4
741 53 spotify:track:7KnQNB3jji26dHsa8juQm4 Relaxation Music, Pt. 27 Relaxing Music by Terry Woodbead, Yoga, Relaxi... #01 Relaxation Music to Unwind, for Sleeping, ... 2022-02-15 27 129879 False 0 ... 7.0 -36.699 0.0 0.0426 0.918 0.920 0.0937 0.0305 98.569 3
742 86 spotify:track:5htB0YnLTMrS4UF3fGNQWT Relaxation Music, Pt. 28 Relaxing Music by Terry Woodbead, Yoga, Relaxi... #01 Relaxation Music to Unwind, for Sleeping, ... 2022-02-15 28 124752 False 0 ... 9.0 -38.419 0.0 0.0436 0.913 0.881 0.1050 0.0349 66.577 4
743 130 spotify:track:4SCq157ayaNbpITwg4dEIy Relaxation Music, Pt. 29 Relaxing Music by Terry Woodbead, Yoga, Relaxi... #01 Relaxation Music to Unwind, for Sleeping, ... 2022-02-15 29 135895 False 0 ... 7.0 -32.885 0.0 0.0420 0.812 0.949 0.0894 0.0439 84.082 3
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
172 119 spotify:track:2zCWdNJUoyysF7ExpA1Vj7 Down To Earth R. Carlos Nakai, Will Clipman, William Eaton Dancing Into Silence 2009-01-01 5 228746 False 25 ... 11.0 -16.509 0.0 0.0320 0.948 0.944 0.0947 0.1210 83.053 4
293 76 spotify:track:2H9Lmrb6cL20hI8nAd9npg Relaxation Raag Jait Ronu Majumdar Music For Pranayam 2008-03-28 4 212976 False 25 ... 4.0 -15.904 1.0 0.0350 0.993 0.855 0.2500 0.1160 76.776 4
847 64 spotify:track:4Zuei1UAP5pB5ovra9dnnp Khwaja Mere Khwaja A.R. Rahman Jodhaa Akbar (Original Motion Picture Soundtrack) 2007-12-31 3 416573 False 58 ... 11.0 -8.003 1.0 0.0333 0.239 0.000 0.1320 0.2600 122.060 4
630 43 spotify:track:1AV71lKV38z6u4rLG9bgZv Den svarta ön, del 19 Tintin, Tomas Bolme, Bert-Åke Varg Den svarta ön 1972-06-19 19 67600 False 25 ... 9.0 -19.866 0.0 0.9150 0.632 0.000 0.3940 0.5350 63.362 4
648 3 spotify:track:3vjU6ogxibljpA3c7D9DDA Den svarta ön, del 35 Tintin, Tomas Bolme, Bert-Åke Varg Den svarta ön 1972-06-19 35 85586 False 24 ... 1.0 -13.001 1.0 0.9370 0.939 0.000 0.2960 0.7960 93.773 5

1287 rows × 24 columns

In [63]:
#from sklearn.preprocessing import StandardScaler
#array= StandardScaler().fit_transform(music[['Danceability', 'Energy','Key','Loudness','Mode','Speechiness','Acousticness','Instrumentalness','Liveness','Valence','Tempo']])
#array
In [64]:
#stmusic= pd.DataFrame(array, columns=['Danceability', 'Energy','Key','Loudness','Mode','Speechiness','Acousticness','Instrumentalness','Liveness','Valence','Tempo']) 
#stmusic
In [65]:
music.dtypes
Out[65]:
user_id                       object
Track_URI                     object
Track_Name                    object
Artist_Name                   object
Album_Name                    object
Album_Release_Date    datetime64[ns]
Track_Number                   int64
Track_Duration(ms)             int64
Explicit                        bool
Popularity                     int64
Added_By                      object
Added_At              datetime64[ns]
Danceability                 float64
Energy                       float64
Key                          float64
Loudness                     float64
Mode                         float64
Speechiness                  float64
Acousticness                 float64
Instrumentalness             float64
Liveness                     float64
Valence                      float64
Tempo                        float64
Time_Signature                 int64
dtype: object
In [66]:
#music.drop(music.iloc[:, 11:22], inplace = True, axis = 1)
In [67]:
music
Out[67]:
user_id Track_URI Track_Name Artist_Name Album_Name Album_Release_Date Track_Number Track_Duration(ms) Explicit Popularity ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time_Signature
730 2 spotify:track:4KxUNwVikOpJyM3AWF87h8 Relaxation Music, Pt. 16 Relaxing Music by Terry Woodbead, Yoga, Relaxi... #01 Relaxation Music to Unwind, for Sleeping, ... 2022-02-15 16 131852 False 0 ... 10.0 -37.285 0.0 0.0456 0.929 0.864 0.1050 0.0379 74.771 4
752 30 spotify:track:0xkRnMADm4cTmaI8damzQq Relaxation Music, Pt. 38 Relaxing Music by Terry Woodbead, Yoga, Relaxi... #01 Relaxation Music to Unwind, for Sleeping, ... 2022-02-15 38 144190 False 0 ... 2.0 -41.150 0.0 0.0426 0.913 0.757 0.0987 0.0346 141.659 4
741 53 spotify:track:7KnQNB3jji26dHsa8juQm4 Relaxation Music, Pt. 27 Relaxing Music by Terry Woodbead, Yoga, Relaxi... #01 Relaxation Music to Unwind, for Sleeping, ... 2022-02-15 27 129879 False 0 ... 7.0 -36.699 0.0 0.0426 0.918 0.920 0.0937 0.0305 98.569 3
742 86 spotify:track:5htB0YnLTMrS4UF3fGNQWT Relaxation Music, Pt. 28 Relaxing Music by Terry Woodbead, Yoga, Relaxi... #01 Relaxation Music to Unwind, for Sleeping, ... 2022-02-15 28 124752 False 0 ... 9.0 -38.419 0.0 0.0436 0.913 0.881 0.1050 0.0349 66.577 4
743 130 spotify:track:4SCq157ayaNbpITwg4dEIy Relaxation Music, Pt. 29 Relaxing Music by Terry Woodbead, Yoga, Relaxi... #01 Relaxation Music to Unwind, for Sleeping, ... 2022-02-15 29 135895 False 0 ... 7.0 -32.885 0.0 0.0420 0.812 0.949 0.0894 0.0439 84.082 3
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
172 119 spotify:track:2zCWdNJUoyysF7ExpA1Vj7 Down To Earth R. Carlos Nakai, Will Clipman, William Eaton Dancing Into Silence 2009-01-01 5 228746 False 25 ... 11.0 -16.509 0.0 0.0320 0.948 0.944 0.0947 0.1210 83.053 4
293 76 spotify:track:2H9Lmrb6cL20hI8nAd9npg Relaxation Raag Jait Ronu Majumdar Music For Pranayam 2008-03-28 4 212976 False 25 ... 4.0 -15.904 1.0 0.0350 0.993 0.855 0.2500 0.1160 76.776 4
847 64 spotify:track:4Zuei1UAP5pB5ovra9dnnp Khwaja Mere Khwaja A.R. Rahman Jodhaa Akbar (Original Motion Picture Soundtrack) 2007-12-31 3 416573 False 58 ... 11.0 -8.003 1.0 0.0333 0.239 0.000 0.1320 0.2600 122.060 4
630 43 spotify:track:1AV71lKV38z6u4rLG9bgZv Den svarta ön, del 19 Tintin, Tomas Bolme, Bert-Åke Varg Den svarta ön 1972-06-19 19 67600 False 25 ... 9.0 -19.866 0.0 0.9150 0.632 0.000 0.3940 0.5350 63.362 4
648 3 spotify:track:3vjU6ogxibljpA3c7D9DDA Den svarta ön, del 35 Tintin, Tomas Bolme, Bert-Åke Varg Den svarta ön 1972-06-19 35 85586 False 24 ... 1.0 -13.001 1.0 0.9370 0.939 0.000 0.2960 0.7960 93.773 5

1287 rows × 24 columns

In [68]:
#music['tmp'] = 1
#stmusic['tmp'] = 1

#music1= pd.merge(music, stmusic, on=['tmp'])
#music=music1.drop('tmp', axis=1)
#music
In [69]:
music.dtypes
Out[69]:
user_id                       object
Track_URI                     object
Track_Name                    object
Artist_Name                   object
Album_Name                    object
Album_Release_Date    datetime64[ns]
Track_Number                   int64
Track_Duration(ms)             int64
Explicit                        bool
Popularity                     int64
Added_By                      object
Added_At              datetime64[ns]
Danceability                 float64
Energy                       float64
Key                          float64
Loudness                     float64
Mode                         float64
Speechiness                  float64
Acousticness                 float64
Instrumentalness             float64
Liveness                     float64
Valence                      float64
Tempo                        float64
Time_Signature                 int64
dtype: object

Visualizing the Data¶

In [70]:
import matplotlib.pyplot as plt
from matplotlib.pyplot import hist
import seaborn as sns
#hist=music.plot(x="Track_Name", y="Popularity", kind='hist')
plt.figure(figsize=(100,30))
plt.bar(music['Track_Name'], music['Popularity'], align='center')
plt.xlabel('Track_Name')
plt.xticks(rotation=90)
plt.ylabel('Popularity',fontsize=80)
plt.yticks(fontsize=50)
plt.title('Bar Chart',fontsize=120)
plt.show()
C:\Users\dell\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:238: RuntimeWarning: Glyph 28057 missing from current font.
  font.set_text(s, 0.0, flags=flags)
C:\Users\dell\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:238: RuntimeWarning: Glyph 27963 missing from current font.
  font.set_text(s, 0.0, flags=flags)
C:\Users\dell\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:238: RuntimeWarning: Glyph 128150 missing from current font.
  font.set_text(s, 0.0, flags=flags)
C:\Users\dell\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:238: RuntimeWarning: Glyph 12643 missing from current font.
  font.set_text(s, 0.0, flags=flags)
C:\Users\dell\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:201: RuntimeWarning: Glyph 28057 missing from current font.
  font.set_text(s, 0, flags=flags)
C:\Users\dell\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:201: RuntimeWarning: Glyph 27963 missing from current font.
  font.set_text(s, 0, flags=flags)
C:\Users\dell\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:201: RuntimeWarning: Glyph 128150 missing from current font.
  font.set_text(s, 0, flags=flags)
C:\Users\dell\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:201: RuntimeWarning: Glyph 12643 missing from current font.
  font.set_text(s, 0, flags=flags)
In [71]:
#counted popularity 
popularity_count=music.groupby('Track_Name')['Popularity'].count().sort_values(ascending=False)
popularity_count
Out[71]:
Track_Name
Relaxing Sleep (Meditation Music)                                                                       23
1 Hour Relaxing Music for Stress Relief. Soothing Music. Meditation. Sleep Music                        17
Brown Noise for Restless Kids: 880 Hz                                                                   16
Down To Earth                                                                                           10
Relaxing Sleep Music • Deep Sleeping Music, Relaxing Music, Stress Relief, Meditation Music (Flying)    10
                                                                                                        ..
Long Road                                                                                                1
Lost in Thought                                                                                          1
Lotus Flower                                                                                             1
Lotus Relaxation                                                                                         1
涙活                                                                                                       1
Name: Popularity, Length: 940, dtype: int64
In [72]:
#creating a dataframe with popularity count
popularity_mean_count= pd.DataFrame(music.groupby('Track_Name')['Popularity'].mean())
popularity_mean_count
Out[72]:
Popularity
Track_Name
1 Hour Relaxing Music for Stress Relief. Soothing Music. Meditation. Sleep Music 0.0
100 Years 0.0
15 Minute Super Deep Meditation Music: Relax Mind Body, Inner Peace, Relaxing Music 0.0
174 Hz: Letting Go Emotional & Physical Pain 36.0
428HZ Frequency Healing Meditation Music 0.0
... ...
Zephyr Sings 0.0
Zona de Concentración 15.0
[Study Sleep Relax 💖] Meditation - music 0.0
Полная релаксация 33.0
涙活 31.0

940 rows × 1 columns

In [73]:
#adding popularity mean count to existing dataframe with popularity
popularity_mean_count['popularity_count'] = pd.DataFrame(music.groupby('Track_Name')['Popularity'].count())
In [74]:
popularity_mean_count
Out[74]:
Popularity popularity_count
Track_Name
1 Hour Relaxing Music for Stress Relief. Soothing Music. Meditation. Sleep Music 0.0 17
100 Years 0.0 1
15 Minute Super Deep Meditation Music: Relax Mind Body, Inner Peace, Relaxing Music 0.0 3
174 Hz: Letting Go Emotional & Physical Pain 36.0 1
428HZ Frequency Healing Meditation Music 0.0 2
... ... ...
Zephyr Sings 0.0 1
Zona de Concentración 15.0 1
[Study Sleep Relax 💖] Meditation - music 0.0 7
Полная релаксация 33.0 1
涙活 31.0 1

940 rows × 2 columns

In [75]:
sns.set_style('dark')
%matplotlib inline

plt.figure(figsize=(20,10))
plt.xlabel("popularity count", fontsize=20)
plt.ylabel("Track count", fontsize=20)
plt.title("Histogram of track count vs popularity", fontsize=30)
plt.rcParams['patch.force_edgecolor'] = True
popularity_mean_count['popularity_count'].hist(bins=50)
Out[75]:
<AxesSubplot:title={'center':'Histogram of track count vs popularity'}, xlabel='popularity count', ylabel='Track count'>
In [76]:
#jointplot
plt.figure(figsize=(8,6))
plt.rcParams['patch.force_edgecolor'] = True
sns.jointplot(x='Popularity', y='popularity_count', data=popularity_mean_count, alpha=0.4)
Out[76]:
<seaborn.axisgrid.JointGrid at 0x289a9610c10>
<Figure size 576x432 with 0 Axes>

Top Ten Popular Songs¶

In [77]:
#count how many rows we have by song, we show only the ten more popular songs 
top_ten = music.groupby('Track_Name')['Popularity'].count().reset_index().sort_values(['Popularity', 'Track_Name'], ascending = [0,1])
top_ten['top_ten']  = round(top_ten['Popularity'].div(top_ten['Popularity'].sum())*100, 2)
In [78]:
top_ten = top_ten[:10]
top_ten
Out[78]:
Track_Name Popularity top_ten
692 Relaxing Sleep (Meditation Music) 23 1.79
0 1 Hour Relaxing Music for Stress Relief. Sooth... 17 1.32
97 Brown Noise for Restless Kids: 880 Hz 16 1.24
180 Down To Earth 10 0.78
693 Relaxing Sleep Music • Deep Sleeping Music, Re... 10 0.78
819 Study Music, Concentration, Focus, Meditation,... 9 0.70
917 Yoga Music, Relaxing Music, Calming Music, Str... 8 0.62
37 Art of Flying 7 0.54
285 Healing Sounds: Cleans the Aura and Space. Rem... 7 0.54
365 Meditating Music 7 0.54
In [79]:
labels = top_ten['Track_Name'].tolist()
counts = top_ten['Popularity'].tolist()
In [80]:
plt.figure()
sns.barplot(x=counts, y=labels, palette='Set3')
sns.despine(left=True, bottom=True)
In [81]:
pip install plotly
Requirement already satisfied: plotly in c:\users\dell\anaconda3\lib\site-packages (5.6.0)
Requirement already satisfied: six in c:\users\dell\anaconda3\lib\site-packages (from plotly) (1.15.0)
Requirement already satisfied: tenacity>=6.2.0 in c:\users\dell\anaconda3\lib\site-packages (from plotly) (8.0.1)
Note: you may need to restart the kernel to use updated packages.
In [82]:
import plotly.express as px 
sound=px.data.gapminder()
sound_features=['Danceability', 'Energy', 'Key', 'Loudness', 'Mode', 'Speechiness', 'Acousticness', 'Instrumentalness', 'Liveness', 'Valence', 'Tempo']
figure=px.line(music, x="Album_Release_Date", y=sound_features)
figure.show()
In [83]:
# how many songs a user listend to
music_grouped=music.groupby(['user_id','Track_Name'])
music_grouped.first()
Out[83]:
Track_URI Artist_Name Album_Name Album_Release_Date Track_Number Track_Duration(ms) Explicit Popularity Added_By Added_At ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time_Signature
user_id Track_Name
1 Between Worlds, Native American spotify:track:1B9OkJj4frUJjrqH6dCd7x Oriental Music Zone Indian Meditation Music Collection – Instrumen... 2017-08-21 17 235887 False 1 spotify:user:31hmjzhlbj4ehjd6qrmh7v4rv6oi 2022-02-15 ... 1.000000 -26.973000 0.000000 0.046900 0.938000 0.970000 0.096700 0.129000 137.553000 3
Power Of Peace - Original Mix spotify:track:7ilBLFs3Q9Mb3xa6si2ICT Sanct Devotional Club Mindful Valley - Relaxing Meditating Music 2021-05-26 31 185600 False 0 spotify:user:31hmjzhlbj4ehjd6qrmh7v4rv6oi 2022-02-15 ... 1.000000 -14.974000 1.000000 0.044100 0.656000 0.956000 0.112000 0.036700 62.693000 3
Relaxation Therapy Music spotify:track:5LkuuUwdyM6cqx0RTMlqTZ Five Senses Meditation Sanctuary Modern Meditation: Fast and Effective Relaxation 2019-08-12 3 203576 False 32 spotify:user:31hmjzhlbj4ehjd6qrmh7v4rv6oi 2022-02-12 ... 10.000000 -17.750000 1.000000 0.036400 0.989000 0.943000 0.079500 0.274000 77.978000 4
Sleep Aid Noise: 720 Hz spotify:track:3xEcxC4SJKbl2kBrhzmNmL Brown Noise Nuts Brown Noise: 720 Hz 2021-11-15 19 62000 False 14 spotify:user:31hmjzhlbj4ehjd6qrmh7v4rv6oi 2022-02-12 ... 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4
Sleeping Flute Music spotify:track:1lIikO2A66vDn2uwR3UZNt Deep Sleep Music DEA Channel, Flute Music Medi... Healing Indian Flute: Calming Native American ... 2021-12-16 1 165233 False 6 spotify:user:31hmjzhlbj4ehjd6qrmh7v4rv6oi 2022-02-15 ... 0.000000 -16.700000 1.000000 0.041500 0.986000 0.915000 0.106000 0.040400 62.264000 3
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
98 Indian Flute Music For Deep Meditation, Relaxation ,Inner Peace, Yoga And Spa spotify:episode:6woGmcr5A67MkTa1uG4sdV Prana Relaxation And Meditation Music Prana Relaxation And Meditation Music 2019-01-12 0 2827050 False 0 spotify:user:31hmjzhlbj4ehjd6qrmh7v4rv6oi 2022-02-15 ... 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4
Reiki Zen Meditation Music,Healing Music, Positive Motivating Energy spotify:episode:73pCD0cQV3KPJERUL8m0bK MEDITATION SELF MEDITATION SELF 2019-01-12 0 3608217 False 0 spotify:user:31hmjzhlbj4ehjd6qrmh7v4rv6oi 2022-02-12 ... 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4
Sarvesham Svastir Bhavtu spotify:track:0ttVqRISNySDktBhdJsJZv Meditative Mind Magical Mantras for Meditation - Volume Two 2015-11-30 4 2717900 False 39 spotify:user:31hmjzhlbj4ehjd6qrmh7v4rv6oi 2022-02-15 ... 0.000000 -21.798000 1.000000 0.036800 0.892000 0.195000 0.089200 0.031500 102.618000 4
99 Meditation on the Beach spotify:track:2jtYyevrJUjP5WoUZ47zmA Buddha Music Sanctuary Meditation TOP 100: Buddha Calm & Peace, 7 Cha... 2016-01-19 44 217282 False 0 spotify:user:31hmjzhlbj4ehjd6qrmh7v4rv6oi 2022-02-12 ... 11.000000 -27.510000 1.000000 0.081600 0.942000 0.001740 0.333000 0.038300 103.135000 4
Pure Feelings spotify:track:2k4sKrKjj8STfBg0gTco4P Relaxing Saxophone Jazz Meditating Saxophone Music 2020-07-14 8 159394 False 18 spotify:user:31hmjzhlbj4ehjd6qrmh7v4rv6oi 2022-02-15 ... 9.000000 -19.544000 0.000000 0.067500 0.962000 0.027900 0.135000 0.584000 183.320000 3

1279 rows × 22 columns

Finding Similarities of Users by Pivot Table¶

In [84]:
music_pivot=music.pivot_table(index='user_id',columns='Track_Name', values='Popularity').reset_index(drop=True)
music_pivot
Out[84]:
Track_Name 1 Hour Relaxing Music for Stress Relief. Soothing Music. Meditation. Sleep Music 100 Years 15 Minute Super Deep Meditation Music: Relax Mind Body, Inner Peace, Relaxing Music 174 Hz: Letting Go Emotional & Physical Pain 428HZ Frequency Healing Meditation Music 528Hz The Miracle Tone A Gentle Raindop A New Day A New You A Precious Moment - Original Mix ... Zen Music Sleep Trigger Zen Spa Music Relaxation Zen Spiritual Music Zen Stones Zendo Zephyr Sings Zona de Concentración [Study Sleep Relax 💖] Meditation - music Полная релаксация 涙活
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 NaN NaN 0.0 NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN 0.0 NaN NaN NaN NaN NaN NaN
4 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
145 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
146 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
147 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
148 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
149 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

150 rows × 940 columns

In [85]:
# Impute those NaNs with 0 values
music_pivot.fillna(0,inplace=True)
music_pivot
Out[85]:
Track_Name 1 Hour Relaxing Music for Stress Relief. Soothing Music. Meditation. Sleep Music 100 Years 15 Minute Super Deep Meditation Music: Relax Mind Body, Inner Peace, Relaxing Music 174 Hz: Letting Go Emotional & Physical Pain 428HZ Frequency Healing Meditation Music 528Hz The Miracle Tone A Gentle Raindop A New Day A New You A Precious Moment - Original Mix ... Zen Music Sleep Trigger Zen Spa Music Relaxation Zen Spiritual Music Zen Stones Zendo Zephyr Sings Zona de Concentración [Study Sleep Relax 💖] Meditation - music Полная релаксация 涙活
0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
3 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
145 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
146 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
147 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
148 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
149 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

150 rows × 940 columns

In [86]:
from sklearn.metrics import pairwise_distances
from scipy.spatial.distance import cosine,correlation
In [87]:
# Calculating Cosine Similarity between Users on array data
music_sim=1-pairwise_distances(music_pivot.values,metric='cosine')
music_sim
Out[87]:
array([[1., 0., 0., ..., 0., 0., 0.],
       [0., 1., 0., ..., 0., 0., 0.],
       [0., 0., 1., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 1., 0., 0.],
       [0., 0., 0., ..., 0., 1., 0.],
       [0., 0., 0., ..., 0., 0., 1.]])
In [88]:
# Store the results in a dataframe format
music_sim1=pd.DataFrame(music_sim)
music_sim1
Out[88]:
0 1 2 3 4 5 6 7 8 9 ... 140 141 142 143 144 145 146 147 148 149
0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
2 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
3 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
4 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.078534 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
145 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 1.0 0.0 0.0 0.0 0.0
146 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.211915 ... 0.0 0.0 0.482729 0.0 0.0 0.0 1.0 0.0 0.0 0.0
147 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 1.0 0.0 0.0
148 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 1.0 0.0
149 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 1.0

150 rows × 150 columns

In [89]:
# Set the index and column names to music ids 
#similarity of each users individually 
music_sim1.index=music['user_id'].unique()
music_sim1.columns=music['user_id'].unique()
music_sim1
Out[89]:
2 30 53 86 130 97 22 133 28 12 ... 99 19 65 88 37 109 128 104 98 21
2 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
30 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
53 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
86 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
130 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.078534 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
109 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 1.0 0.0 0.0 0.0 0.0
128 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.211915 ... 0.0 0.0 0.482729 0.0 0.0 0.0 1.0 0.0 0.0 0.0
104 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 1.0 0.0 0.0
98 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 1.0 0.0
21 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 1.0

150 rows × 150 columns

In [90]:
#every user is similar to themselves so not considering it 
# Nullifying diagonal values
np.fill_diagonal(music_sim,0)
music_sim1
Out[90]:
2 30 53 86 130 97 22 133 28 12 ... 99 19 65 88 37 109 128 104 98 21
2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
30 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
53 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
86 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
130 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.078534 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
109 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
128 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.211915 ... 0.0 0.0 0.482729 0.0 0.0 0.0 0.0 0.0 0.0 0.0
104 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
98 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0
21 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.000000 0.0 0.000000 ... 0.0 0.0 0.000000 0.0 0.0 0.0 0.0 0.0 0.0 0.0

150 rows × 150 columns

In [91]:
# displaying Most Similar Users
music_sim1.idxmax(axis=1)
Out[91]:
2       56
30     125
53       2
86     124
130     64
      ... 
109    149
128     65
104      2
98     136
21       2
Length: 150, dtype: object
In [92]:
music1=music.sort_index() 
music1
Out[92]:
user_id Track_URI Track_Name Artist_Name Album_Name Album_Release_Date Track_Number Track_Duration(ms) Explicit Popularity ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time_Signature
0 41 spotify:track:4wDkM4eonFlMpw07mQxZbM Meditation Awaken Chakra Healing Music Academy Genius Brain Frequency: Top 100 Chakra Healing... 2022-01-04 20 225000 False 5 ... 0.000000 -23.311000 1.000000 0.036600 0.986000 0.872000 0.088400 0.036800 75.166000 4
1 29 spotify:track:0dLkW1wbEi6nzyLQOwNCMv Yoga Top 100 Yoga Training Music Ensemble, Healing Yoga Med... Anxiety Meditation and Yoga for Insecurity: Re... 2021-09-07 3 255384 False 1 ... 5.000000 -22.049000 1.000000 0.049900 0.922000 0.917000 0.101000 0.037200 88.407000 4
2 102 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0 415056 False 0 ... 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4
3 150 spotify:track:1oVgCauMXygkALiOtI51M1 Yoga Top 100 Namaste Healing Yoga Zen Meditation Music 111: Relaxing Flute Piano... 2016-05-23 25 252512 False 8 ... 10.000000 -24.113000 1.000000 0.042100 0.843000 0.947000 0.130000 0.053400 102.475000 3
4 8 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0 112941 False 0 ... 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1282 136 spotify:track:52bpdusCUIPfzrRZ8n4FRP Maitri Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 26 346402 False 0 ... 2.000000 -18.944000 1.000000 0.042400 0.929000 0.954000 0.092200 0.038400 70.205000 5
1283 133 spotify:track:71kayL70PNWQIHWt5P8uhU Spiritual Teacher Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 27 285372 False 0 ... 2.000000 -20.522000 0.000000 0.043300 0.991000 0.989000 0.085100 0.034000 75.706000 3
1284 45 spotify:track:77PyhSbcu8ctjPbVGSwaa9 Chakra Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 28 272816 False 0 ... 11.000000 -29.692000 0.000000 0.044600 0.968000 0.975000 0.137000 0.034200 64.739000 3
1285 64 spotify:track:3vmjzmOGGlPczWQWNf7cE0 Elixir Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 29 253226 False 0 ... 10.000000 -21.052000 0.000000 0.076900 0.990000 0.915000 0.129000 0.049200 65.566000 5
1286 36 spotify:track:5AJIr4CC0Te4HOofAtmYa8 Kundalini Yoga Ambience, Soothing White Noise for Infant... # Fresh Therapy 2019-10-09 30 245496 False 0 ... 3.000000 -28.018000 1.000000 0.038700 0.982000 0.986000 0.115000 0.049600 68.935000 4

1287 rows × 24 columns

In [93]:
music1.head(10)
Out[93]:
user_id Track_URI Track_Name Artist_Name Album_Name Album_Release_Date Track_Number Track_Duration(ms) Explicit Popularity ... Key Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time_Signature
0 41 spotify:track:4wDkM4eonFlMpw07mQxZbM Meditation Awaken Chakra Healing Music Academy Genius Brain Frequency: Top 100 Chakra Healing... 2022-01-04 20 225000 False 5 ... 0.000000 -23.311000 1.000000 0.036600 0.986000 0.872000 0.088400 0.036800 75.166000 4
1 29 spotify:track:0dLkW1wbEi6nzyLQOwNCMv Yoga Top 100 Yoga Training Music Ensemble, Healing Yoga Med... Anxiety Meditation and Yoga for Insecurity: Re... 2021-09-07 3 255384 False 1 ... 5.000000 -22.049000 1.000000 0.049900 0.922000 0.917000 0.101000 0.037200 88.407000 4
2 102 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0 415056 False 0 ... 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4
3 150 spotify:track:1oVgCauMXygkALiOtI51M1 Yoga Top 100 Namaste Healing Yoga Zen Meditation Music 111: Relaxing Flute Piano... 2016-05-23 25 252512 False 8 ... 10.000000 -24.113000 1.000000 0.042100 0.843000 0.947000 0.130000 0.053400 102.475000 3
4 8 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0 112941 False 0 ... 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4
5 68 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0 415056 False 0 ... 4.766784 -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4
6 12 spotify:track:2sC671jfJK3yoXUchjBjT5 Buddha Meditation Buddha Music Sanctuary Meditation TOP 100: Buddha Calm & Peace, 7 Cha... 2016-01-19 1 168630 False 2 ... 11.000000 -20.416000 1.000000 0.042900 0.080600 0.783000 0.103000 0.036100 113.503000 5
7 143 spotify:track:0SlkoLU94Jb9QeuchdOXWi Mindscape Buddha Music Sanctuary Meditation TOP 100: Buddha Calm & Peace, 7 Cha... 2016-01-19 2 189806 False 0 ... 9.000000 -21.898000 1.000000 0.049200 0.981000 0.390000 0.110000 0.174000 124.294000 4
8 97 spotify:track:0SlkoLU94Jb9QeuchdOXWi Mindscape Buddha Music Sanctuary Meditation TOP 100: Buddha Calm & Peace, 7 Cha... 2016-01-19 2 189806 False 0 ... 9.000000 -21.898000 1.000000 0.049200 0.981000 0.390000 0.110000 0.174000 124.294000 4
9 11 spotify:track:4N0V2ATgQAWZM4mqzv3gUL Drifting Spirit: Journey to Peace Buddha Music Sanctuary Meditation TOP 100: Buddha Calm & Peace, 7 Cha... 2016-01-19 5 205609 False 0 ... 6.000000 -27.497000 0.000000 0.746000 0.913000 0.271000 0.201000 0.080200 107.068000 3

10 rows × 24 columns

PCA¶

In [94]:
from sklearn.decomposition import PCA
In [95]:
# define transform
pca = PCA(n_components=1)
# prepare transform on dataset
pca.fit(music.iloc[:,12:23])
# apply transform to dataset
transformed = pca.transform(music.iloc[:,12:23])
In [96]:
transformed
Out[96]:
array([[ 21.82693979],
       [-44.89886907],
       [ -1.97957606],
       ...,
       [-26.42445821],
       [ 32.63863824],
       [  2.00743197]])
In [97]:
pca.components_
Out[97]:
array([[-9.64888128e-04, -4.19265298e-04,  7.92261009e-04,
        -3.37474395e-02,  1.70250420e-04, -8.11714580e-05,
         9.75293893e-04,  9.07587599e-04, -1.21486284e-04,
        -3.37993592e-04, -9.99428555e-01]])
In [98]:
# Final Dataframe
final_df=pd.DataFrame(transformed)
final_df
Out[98]:
0
0 21.826940
1 -44.898869
2 -1.979576
3 30.053730
4 12.370387
... ...
1282 12.849060
1283 19.096775
1284 -26.424458
1285 32.638638
1286 2.007432

1287 rows × 1 columns

In [99]:
pca1= final_df.rename(columns={0: 'PC1'})  
pca1
Out[99]:
PC1
0 21.826940
1 -44.898869
2 -1.979576
3 30.053730
4 12.370387
... ...
1282 12.849060
1283 19.096775
1284 -26.424458
1285 32.638638
1286 2.007432

1287 rows × 1 columns

In [100]:
pc= music1.append(pca1, ignore_index=False)
pc
Out[100]:
user_id Track_URI Track_Name Artist_Name Album_Name Album_Release_Date Track_Number Track_Duration(ms) Explicit Popularity ... Loudness Mode Speechiness Acousticness Instrumentalness Liveness Valence Tempo Time_Signature PC1
0 41 spotify:track:4wDkM4eonFlMpw07mQxZbM Meditation Awaken Chakra Healing Music Academy Genius Brain Frequency: Top 100 Chakra Healing... 2022-01-04 20.0 225000.0 False 5.0 ... -23.311000 1.000000 0.036600 0.986000 0.872000 0.088400 0.036800 75.166000 4.0 NaN
1 29 spotify:track:0dLkW1wbEi6nzyLQOwNCMv Yoga Top 100 Yoga Training Music Ensemble, Healing Yoga Med... Anxiety Meditation and Yoga for Insecurity: Re... 2021-09-07 3.0 255384.0 False 1.0 ... -22.049000 1.000000 0.049900 0.922000 0.917000 0.101000 0.037200 88.407000 4.0 NaN
2 102 spotify:episode:6tpsPNJECk1eLbsPJgXNBR Meditation - Naval Ravikant Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0.0 415056.0 False 0.0 ... -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4.0 NaN
3 150 spotify:track:1oVgCauMXygkALiOtI51M1 Yoga Top 100 Namaste Healing Yoga Zen Meditation Music 111: Relaxing Flute Piano... 2016-05-23 25.0 252512.0 False 8.0 ... -24.113000 1.000000 0.042100 0.843000 0.947000 0.130000 0.053400 102.475000 3.0 NaN
4 8 spotify:episode:5fLpnfOalU991SfSu9r7z8 Meditation - by A Monk Self Improvement through Top 100 Books Self Improvement through Top 100 Books 2019-01-12 0.0 112941.0 False 0.0 ... -25.155986 0.675795 0.061512 0.831158 0.798753 0.185348 0.093422 96.196466 4.0 NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1282 NaN NaN NaN NaN NaN NaT NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 12.849060
1283 NaN NaN NaN NaN NaN NaT NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 19.096775
1284 NaN NaN NaN NaN NaN NaT NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN -26.424458
1285 NaN NaN NaN NaN NaN NaT NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 32.638638
1286 NaN NaN NaN NaN NaN NaT NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 2.007432

2574 rows × 25 columns

In [101]:
pc['PC1'].isnull()
Out[101]:
0        True
1        True
2        True
3        True
4        True
        ...  
1282    False
1283    False
1284    False
1285    False
1286    False
Name: PC1, Length: 2574, dtype: bool

Music Similarity¶

In [102]:
from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(max_features=500,stop_words='english')
In [103]:
vector = cv.fit_transform(music1['Track_Name'].unique()).toarray()
In [104]:
vector.shape
Out[104]:
(940, 500)
In [105]:
from sklearn.metrics.pairwise import cosine_similarity
similarity = cosine_similarity(vector)
similarity
Out[105]:
array([[1.        , 0.        , 0.70710678, ..., 0.        , 0.        ,
        0.        ],
       [0.        , 1.        , 0.        , ..., 0.        , 0.        ,
        0.        ],
       [0.70710678, 0.        , 1.        , ..., 0.        , 0.        ,
        0.        ],
       ...,
       [0.        , 0.        , 0.        , ..., 1.        , 0.        ,
        0.        ],
       [0.        , 0.        , 0.        , ..., 0.        , 0.        ,
        0.        ],
       [0.        , 0.        , 0.        , ..., 0.        , 0.        ,
        1.        ]])
In [106]:
similarity[2]
Out[106]:
array([0.70710678, 0.        , 1.        , 0.70710678, 0.5       ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.5       , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.35355339, 0.        , 0.        , 0.        , 0.        ,
       0.5       , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.70710678, 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.5       , 0.        , 0.        , 0.31622777,
       0.5       , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.18898224, 0.40824829,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.35355339,
       0.        , 0.        , 0.40824829, 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.35355339, 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.70710678, 0.        , 0.        , 0.40824829, 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.2236068 ,
       0.35355339, 0.2236068 , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.70710678, 0.        , 0.        ,
       0.        , 0.5       , 0.5       , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.5       , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.40824829, 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.5       ,
       0.31622777, 0.13608276, 0.16666667, 0.1767767 , 0.2236068 ,
       0.15075567, 0.        , 0.        , 0.5       , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.31622777,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.40824829,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.5       , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.35355339, 0.        , 0.        , 0.        , 0.        ,
       0.35355339, 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.31622777, 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.40824829,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.5       , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.40824829, 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.40824829, 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.31622777,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.40824829, 0.40824829, 0.40824829, 0.40824829, 0.40824829,
       0.35355339, 0.35355339, 0.35355339, 0.35355339, 0.35355339,
       0.35355339, 0.35355339, 0.35355339, 0.35355339, 0.35355339,
       0.35355339, 0.35355339, 0.35355339, 0.35355339, 0.35355339,
       0.35355339, 0.35355339, 0.35355339, 0.35355339, 0.35355339,
       0.40824829, 0.40824829, 0.40824829, 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.14433757,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.25      , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.31622777,
       0.1767767 , 0.23570226, 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.31622777, 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.5       , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.31622777, 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.31622777, 0.        ,
       0.        , 0.35355339, 0.        , 0.35355339, 0.        ,
       0.        , 0.        , 0.17149859, 0.12700013, 0.        ,
       0.18898224, 0.23570226, 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.5       ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.40824829, 0.40824829, 0.40824829,
       0.35355339, 0.35355339, 0.35355339, 0.35355339, 0.35355339,
       0.35355339, 0.35355339, 0.35355339, 0.35355339, 0.35355339,
       0.35355339, 0.35355339, 0.35355339, 0.35355339, 0.35355339,
       0.35355339, 0.35355339, 0.35355339, 0.35355339, 0.40824829,
       0.40824829, 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ,
       0.        , 0.        , 0.        , 0.        , 0.        ])
In [107]:
#index of perticular song 
music1[music1['Track_Name'] == 'Yoga Top 100'].index[0]
Out[107]:
1

Deployment¶

In [108]:
def recommend(music):
    index = music1[music1['Track_Name'] == music].index[0]
    distances = sorted(list(enumerate(similarity[index])),reverse=True,key = lambda x: x[1])
 
    for i in distances[1:11]:
        a=[(music1.iloc[i[0]].Track_Name)],[(music1.iloc[i[0]].Artist_Name)]
#         data= pd.DataFrame(a, columns =['Track Name', 'Artist Name'],index =[i[0]])
        print(a)
    
In [109]:
recommend('Mindscape')
(['Meditation Awaken'], ['Chakra Healing Music Academy'])
(['Yoga Top 100'], ['Yoga Training Music Ensemble, Healing Yoga Meditation Music Consort, Relaxing Zen Music Ensemble\\, Nature Meditation Academy'])
(['Meditation - Naval Ravikant'], ['Self Improvement through Top 100 Books'])
(['Yoga Top 100'], ['Namaste Healing Yoga'])
(['Meditation - by A Monk'], ['Self Improvement through Top 100 Books'])
(['Meditation - Naval Ravikant'], ['Self Improvement through Top 100 Books'])
(['Buddha Meditation'], ['Buddha Music Sanctuary'])
(['Mindscape'], ['Buddha Music Sanctuary'])
(['Drifting Spirit: Journey to Peace'], ['Buddha Music Sanctuary'])
(['Zephyr Sings'], ['Buddha Music Sanctuary'])
In [110]:
import pickle 
In [111]:
pickle.dump(music1,open('music.pkl','wb'))
In [112]:
pickle.dump(similarity,open('similarity.pkl','wb'))

Explanation:¶

import pickle

# Save the 'music1' object
pickle.dump(music1, open('music.pkl', 'wb'))

# Save the 'similarity' object
pickle.dump(similarity, open('similarity.pkl', 'wb'))

print("Data serialization completed successfully.")

# Optionally, you can add further instructions or notes here
# such as how to load these pickle files later, or any
# additional steps needed after saving.
  • print("Data serialization completed successfully."): This line informs the user that the data serialization process (using pickle.dump) has been executed without errors. It's a good practice to provide feedback to confirm that the operation completed as intended.

  • Optional Instructions: Depending on your specific needs, you might want to include additional instructions or notes about the saved pickle files. For example, you could mention how to load these files back into Python objects using pickle.load, or any precautions to be aware of when handling these files.

Conclusion¶

  • Project Overview: The music recommendation system for meditation and relaxation leverages Spotify's extensive dataset to provide personalized recommendations based on various musical attributes.

  • Dataset Understanding: The dataset includes comprehensive information such as track names, artists, album details, popularity metrics, and audio features like danceability, energy, and acousticness.

  • System Development: Developed a robust system using Python and relevant libraries to analyze and recommend tracks suitable for calming and soothing experiences.

  • Model Building: Utilized similarity metrics and possibly machine learning algorithms to enhance recommendation accuracy, ensuring that recommended tracks align closely with user preferences for meditation and relaxation.

  • Feature Importance: Identified key features such as acousticness, instrumentalness, and valence as crucial indicators for selecting appropriate music for relaxation purposes.

  • User Experience Considerations: Incorporated user feedback mechanisms or rating systems to continually refine recommendations and enhance user satisfaction over time.

  • Performance Evaluation: Conducted rigorous testing and evaluation of the recommendation system to validate its effectiveness in providing relevant and enjoyable music selections.


Key Recommendations¶

  • Enhanced Personalization: Implement more advanced machine learning techniques (e.g., collaborative filtering, deep learning) to further personalize recommendations based on individual listening habits and preferences.

  • Real-time Updates: Integrate real-time data streaming capabilities to ensure that recommendations are continuously updated based on the latest user interactions and new music releases.

  • User Interface Optimization: Improve the user interface with intuitive controls for selecting mood preferences or relaxation goals, making it easier for users to find suitable music effortlessly.

  • Expand Dataset Coverage: Continuously expand the dataset to include a wider variety of meditation-specific music genres and styles, ensuring a richer selection pool for users.

  • Incorporate Feedback Mechanisms: Develop mechanisms for users to provide feedback on recommended tracks, helping to refine algorithms and improve future recommendations.

  • Ethical Considerations: Ensure transparency in data usage and recommendation processes, respecting user privacy and preferences while delivering personalized experiences.


Future Directions¶

  • Integration with Wearable Technology: Explore integration possibilities with wearable devices to dynamically adjust music recommendations based on user biometric data (e.g., heart rate, stress levels).

  • Natural Language Processing: Incorporate natural language processing techniques to analyze user reviews and comments, extracting insights to enhance recommendation accuracy.

  • Global Expansion: Consider localization strategies to adapt the recommendation system for global audiences, taking into account cultural preferences and regional music trends.

  • Partnerships and Collaborations: Forge partnerships with meditation apps, wellness platforms, or music therapy organizations to further validate and promote the system's effectiveness in promoting relaxation and well-being.

By implementing these recommendations and exploring future directions, the music recommendation system can continue to evolve and provide valuable services to users seeking personalized and enriching musical experiences for meditation and relaxation purposes.